# try to solve the josephus Problem (m,n) in python in O(n)
# author :timlentse(tinglenxan@gmail.com)
# Date:2014-11-13
#! usr/bin/python 
def josephSolution(n,m):
    if n==1:
        return 0
    s=0
    for i in xrange(2,n+1):
        s = (s+m)%i
    return s;
n = raw_input('input n =')
m = raw_input('input m =')
solution = josephSolution(int(n),int(m))
print 'The luckly number is ', solution+1;
        